﻿using AutoMapper;
using Dapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Productionorderss;

namespace MyMES.Writer.API.Application.CommendHandlers.Productionorderss
{
    public class CreateWorkderupdataZtCommendHandlers : IRequestHandler<CreateWorkderupdataZtCommends, APIResult<woekderProess>>
    {
        private readonly IBaseRepository<woekderProess> woekdersRepository;
        private readonly IMapper mapper;
        public DatabaseContext db;

        public CreateWorkderupdataZtCommendHandlers(IBaseRepository<woekderProess> woekdersRepository, IMapper mapper, DatabaseContext db)
        {
            this.woekdersRepository = woekdersRepository;
            this.mapper = mapper;
            this.db = db;
        }


        /// <summary>
        /// 添加并修改状态--报工记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async Task<APIResult<woekderProess>> Handle(CreateWorkderupdataZtCommends request, CancellationToken cancellationToken)
        {

            APIResult < woekderProess > result = new APIResult<woekderProess>();
            result.Code = APIEnum.添加成功;
            result.Msg = "修改状态成功";
            var pro = mapper.Map<woekderProess>(request);
            string sql = "UPDATE woekderproess SET     Goodproduct = @Goodproduct,Notproduct =@Notproduct,Zt=@Zt WHERE   woekderProessId= @woekderProessId ";
        await   woekdersRepository.Update(pro, sql);
            result.data = pro;
            return result;
        }
    }
    }

